import axios from '@/utils/request'
export default {
  StoreCounterCategory: {
    entity: { name: 'Category', prefix: () => `store/${localStorage.getItem('storeId')}` },
    form: {
      fields: [
        'name',
        {
          property: 'type',
          component: {
            props: ['form', 'property'],
            data() {
              return { data: [] }
            },
            created() {
              axios.get(`/api/types`, {
                params: {
                  '@filter': 'entity.getSlug() == "counter"',
                  'limit': 1000000
                }
              }).then((res) => {
                console.log(res)
                if (res.data != null) {
                  this.form[this.property] = res.data[0].id
                  this.data = res.data
                }
              })
            },
            render(h) {
              return (
                <el-select v-model={this.form[this.property]} clearable disabled={true}>{
                  Object.assign(this.data).map(v => {
                    return <el-option key={v.id} label={v.name} value={v.id} />
                  })
                }</el-select>
              )
            }
          }
        },
        // { property: 'parent', required: false },
        { property: 'enabled', required: false, default_value: true },
        { property: 'sequence', required: false, default_value: 0 },
        { property: 'icon', required: false, type: 'image' }
      ]
    },
    list: {
      query: {
        '@filter': 'entity.getType().getSlug() == "counter"'
      },
      list_display: [
        'id',
        'type',
        'name',
        // 'parent',
        'enabled',
        'sequence'
      ],
      list_filter: {
      }
    }
  }
}

